package com.tubang.logistics.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.tubang.common.constant.Constants;
import com.tubang.logistics.entity.LogisticsOrderGoodsEntity;
import com.tubang.logistics.mapper.LogisticsOrderGoodsMapper;
import com.tubang.logistics.service.ILogisticsOrderGoodsService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 物流公司运单-货品 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2017-12-31
 */
@Service
public class LogisticsOrderGoodsServiceImpl extends ServiceImpl<LogisticsOrderGoodsMapper, LogisticsOrderGoodsEntity> implements ILogisticsOrderGoodsService {

    @Override
    public List<LogisticsOrderGoodsEntity> selectOrderByOrderId(String id, Integer status) {
        EntityWrapper<LogisticsOrderGoodsEntity> entityWrapper = new EntityWrapper<LogisticsOrderGoodsEntity>();
        entityWrapper.eq("logistics_order_id", id);
        if (status != null) {
            entityWrapper.eq("status_code", status);
        }
        List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntitys = selectList(entityWrapper);
        return logisticsOrderGoodsEntitys;
    }

    @Override
    public void upDataOrderGoodsService(List<String> goodsIds) {
        for (String goodsId : goodsIds) {
            LogisticsOrderGoodsEntity logisticsOrderGoodsEntity = selectOrderByGoodsId(goodsId, Integer.valueOf(Constants.DEFAULT_VAULE_ONE));
            if (logisticsOrderGoodsEntity == null) continue;
            logisticsOrderGoodsEntity.setStatusCode(Constants.DEFAULT_VAULE_ZERO);
            logisticsOrderGoodsEntity.setStatusCodeDesc("已调度");
            insertOrUpdate(logisticsOrderGoodsEntity);
        }

    }

    @Override
    public List<LogisticsOrderGoodsEntity> selectOrdersByGoodsId(String goodsId) {
        EntityWrapper<LogisticsOrderGoodsEntity> entityWrapper = new EntityWrapper<LogisticsOrderGoodsEntity>();
        entityWrapper.eq("goods_id", goodsId);
        List<LogisticsOrderGoodsEntity> logisticsOrderGoodsEntities = selectList(entityWrapper);
        return logisticsOrderGoodsEntities;
    }

    @Override
    public LogisticsOrderGoodsEntity selectOrderByGoodsId(String id, Integer status) {
        EntityWrapper<LogisticsOrderGoodsEntity> entityWrapper = new EntityWrapper<LogisticsOrderGoodsEntity>();
        entityWrapper.eq("goods_id", id);
        if (status != null) {
            entityWrapper.eq("status_code", status);
        }
        LogisticsOrderGoodsEntity logisticsOrderGoodsEntity = selectOne(entityWrapper);
        return logisticsOrderGoodsEntity;
    }
}
